<?php
/**
 * Author   : 葫芦瓢子 <gourdladle@163.com>
 * Date     : 2023-06-29
 * Wechat   : skymouses
 * License  : MIT
 */

namespace GourdLadle\PhinxTp;

use GourdLadle\PhinxTp\Status;
use GourdLadle\PhinxTp\migrate\Create;
use GourdLadle\PhinxTp\migrate\Run;
use GourdLadle\PhinxTp\migrate\Rollback;
use GourdLadle\PhinxTp\seed\Create as CreateSeed;
use GourdLadle\PhinxTp\seed\Run as RunSeed;

class Service extends \think\Service
{
    public function boot()
    {
        $this->commands([
            Status::class,
            Create::class,
            Run::class,
            Rollback::class,
            CreateSeed::class,
            RunSeed::class,
        ]);

        $this->makeDir();
    }

    public function makeDir()
    {
        $rootDir = getcwd();
        $paths = [
            $rootDir.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'migrations',
            $rootDir.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'seeds',
        ];
        foreach($paths as $path){
            if(!file_exists($path)){
                mkdir($path, 0755, true);
            }
        }
    }
}